<?php
/**
 * Created by PhpStorm.
 * User: henryxi-mac
 * Date: 2015/6/17
 * Time: 13:20
 */

require_once dirname(__FILE__)."/lib/common.php";
require_once dirname(__FILE__)."/config.php";
global $db_config;
$db = new mysql($db_config);
$ptime=date("Ymd",time());
//统计pv和uv
$sql='select * from pv where puttime='.$ptime;
$ret = $db->sql($sql);

if(is_array($ret) && $ret[0]){
    $total=$ret[0]['pvnum'] +1;
    $sqlup="update pv set pvnum=$total where puttime=".$ptime;
    $rt=$db->sql($sqlup);
}else{
    $sql2="insert into pv(pvnum,puttime) values(1,{$ptime})";
    $rs = $db->sql($sql2);
}
//uv统计
function getIP()
{
    $ip=getenv('REMOTE_ADDR');
    $ip_ = getenv('HTTP_X_FORWARDED_FOR');
    if (($ip_ != "") && ($ip_ != "unknown"))
    {
        $ip=$ip_;
    }
    return $ip;
}
$ipinfo = getIP();
$sqlu="select * from uv where  uvip='".$ipinfo."' and uvtime=".$ptime;
$ret = $db->sql($sqlu);
if(!$ret[0]){
    $sqluv="insert into uv(uvip,uvtime) values('{$ipinfo}',$ptime)";
    $rt = $db->sql($sqluv);
}